API: Add GtkStyleContext::parent
authorBenjamin Otte <otte@redhat.com>
Thu, 29 Dec 2011 11:30:25 +0000 (12:30 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Jan 2012 17:37:50 +0000 (18:37 +0100)
We need this for proper support of CSS inherit.

docs/reference/gtk/gtk3-sections.txt
gtk/gtk.symbols
gtk/gtkstylecontext.c
gtk/gtkstylecontext.h

index 3bfde4faefd469eb16b2f8002c02fa06c6c19795..55049f74092d6e32ce47457aa2b1ebc98c072bb0 100644 (file)
@@ -5680,6 +5680,7 @@ gtk_style_context_add_provider_for_screen
 gtk_style_context_get
 gtk_style_context_get_direction
 gtk_style_context_get_junction_sides
+gtk_style_context_set_parent
 gtk_style_context_get_path
 gtk_style_context_get_property
 gtk_style_context_get_screen
@@ -5712,6 +5713,7 @@ gtk_style_context_restore
 gtk_style_context_save
 gtk_style_context_set_direction
 gtk_style_context_set_junction_sides
+gtk_style_context_set_parent
 gtk_style_context_set_path
 gtk_style_context_add_class
 gtk_style_context_remove_class
index 7891d3cc53f8185d60068722c2b1eeef5555ad35..f852ff29e142aeee32abb4236c891f117d64232c 100644 (file)
@@ -2539,6 +2539,7 @@ gtk_style_context_get_font
 gtk_style_context_get_junction_sides
 gtk_style_context_get_margin
 gtk_style_context_get_padding
+gtk_style_context_get_parent
 gtk_style_context_get_path
 gtk_style_context_get_property
 gtk_style_context_get_screen
@@ -2570,6 +2571,7 @@ gtk_style_context_scroll_animations
 gtk_style_context_set_background
 gtk_style_context_set_direction
 gtk_style_context_set_junction_sides
+gtk_style_context_set_parent
 gtk_style_context_set_path
 gtk_style_context_set_screen
 gtk_style_context_set_state
index f4bd0d00f74e2e07c3605bd29b56965ca43e557c..21205c3ee86d1bcdbcb2c317de3deca2a4897100 100644 (file)
@@ -368,6 +368,7 @@ struct _GtkStyleContextPrivate
   GList *providers;
   GList *providers_last;
 
+  GtkStyleContext *parent;
   GtkWidgetPath *widget_path;
   GHashTable *style_data;
   GSList *info_stack;
@@ -388,7 +389,8 @@ struct _GtkStyleContextPrivate
 enum {
   PROP_0,
   PROP_SCREEN,
-  PROP_DIRECTION
+  PROP_DIRECTION,
+  PROP_PARENT
 };
 
 enum {
@@ -450,6 +452,21 @@ gtk_style_context_class_init (GtkStyleContextClass *klass)
                                                       GTK_TYPE_TEXT_DIRECTION,
                                                       GTK_TEXT_DIR_LTR,
                                                       GTK_PARAM_READWRITE));
+  /**
+   * GtkStyleContext:parent:
+   *
+   * Sets or gets the style context's parent. See gtk_style_context_set_parent()
+   * for details.
+   *
+   * Since: 3.4
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_PARENT,
+                                   g_param_spec_object ("parent",
+                                                        P_("Parent"),
+                                                        P_("The parent style context"),
+                                                        GTK_TYPE_STYLE_CONTEXT,
+                                                        GTK_PARAM_READWRITE));
 
   g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
 }
@@ -807,6 +824,8 @@ gtk_style_context_finalize (GObject *object)
   style_context = GTK_STYLE_CONTEXT (object);
   priv = style_context->priv;
 
+  gtk_style_context_set_parent (style_context, NULL);
+
   if (priv->widget_path)
     gtk_widget_path_free (priv->widget_path);
 
@@ -849,6 +868,10 @@ gtk_style_context_impl_set_property (GObject      *object,
       gtk_style_context_set_direction (style_context,
                                        g_value_get_enum (value));
       break;
+    case PROP_PARENT:
+      gtk_style_context_set_parent (style_context,
+                                    g_value_get_object (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -875,6 +898,9 @@ gtk_style_context_impl_get_property (GObject    *object,
     case PROP_DIRECTION:
       g_value_set_enum (value, priv->direction);
       break;
+    case PROP_PARENT:
+      g_value_set_object (value, priv->parent);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1661,6 +1687,66 @@ gtk_style_context_get_path (GtkStyleContext *context)
   return priv->widget_path;
 }
 
+/**
+ * gtk_style_context_set_parent:
+ * @context: a #GtkStyleContext
+ * @parent: (allow-none): the new parent or %NULL
+ *
+ * Sets the parent style context for @context. The parent style
+ * context is used to implement
+ * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance>
+ * inheritance</ulink> of properties.
+ *
+ * If you are using a #GtkStyleContext returned from
+ * gtk_widget_get_style_context(), the parent will be set for you.
+ *
+ * Since: 3.4
+ **/
+void
+gtk_style_context_set_parent (GtkStyleContext *context,
+                              GtkStyleContext *parent)
+{
+  GtkStyleContextPrivate *priv;
+
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+  g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
+
+  priv = context->priv;
+
+  if (priv->parent == parent)
+    return;
+
+  if (parent)
+    g_object_ref (parent);
+
+  if (priv->parent)
+    g_object_unref (priv->parent);
+
+  priv->parent = parent;
+
+  g_object_notify (G_OBJECT (context), "parent");
+  gtk_style_context_invalidate (context);
+}
+
+/**
+ * gtk_style_context_get_parent:
+ * @context: a #GtkStyleContext
+ *
+ * Gets the parent context set via gtk_style_context_set_parent().
+ * See that function for details.
+ *
+ * Returns: (transfer none): the parent context or %NULL
+ *
+ * Since: 3.4
+ **/
+GtkStyleContext *
+gtk_style_context_get_parent (GtkStyleContext *context)
+{
+  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
+
+  return context->priv->parent;
+}
+
 /**
  * gtk_style_context_save:
  * @context: a #GtkStyleContext
index 0dfb4769c69ddf053e25211ad77f30092c33d91b..afdeb7b686534ae8053f9e26c54942b027b8c37f 100644 (file)
@@ -740,6 +740,10 @@ void          gtk_style_context_set_path     (GtkStyleContext *context,
                                               GtkWidgetPath   *path);
 const GtkWidgetPath * gtk_style_context_get_path (GtkStyleContext *context);
 
+void          gtk_style_context_set_parent   (GtkStyleContext *context,
+                                              GtkStyleContext *parent);
+GtkStyleContext *gtk_style_context_get_parent (GtkStyleContext *context);
+
 GList *  gtk_style_context_list_classes (GtkStyleContext *context);
 
 void     gtk_style_context_add_class    (GtkStyleContext *context,